// 默认分页 size
export const PAGE_SIZE = 10;
export const COPY_RIGHT = 'WMS管理系统 ©2017';
// 默认 message显示时间
export const ERROR_MSG_DURATION = 3;
// 任务类型 start
export const TASK_TYPE = {
  REALTIME: 1, // 实时任务
  TIMING: 2, // 定时任务
  CRON: 3, // cron任务
  REPEAT: 4, // repeat任务
};
// 根据任务类型获取任务类型名称
export const getTaskTypeName = (taskType) => {
  switch (Number(taskType)) {
    case TASK_TYPE.REALTIME: return '实时任务';
    case TASK_TYPE.TIMING: return '定时任务';
    case TASK_TYPE.CRON: return 'CRON任务';
    case TASK_TYPE.REPEAT: return 'REPEAT任务';
    default: return '未知任务类型';
  }
};
// 任务类型end

// 节点类型
export const NODE_TYPE = {
  JOB_CLIENT: 'JOB_CLIENT',
  JOB_TRACKER: 'JOB_TRACKER',
  TASK_TRACKER: 'TASK_TRACKER',
  MONITOR: 'MONITOR',
};

// 任务状态start
export const TASK_STATUS = {
  RUNNING: 1,
  PAUSE: 2,
  FINISHED: 3,
  FAILED: 4,
};
// 根据任务状态获取任务状态名称
export const getTaskStatusName = (taskStatus) => {
  switch (Number(taskStatus)) {
    case TASK_STATUS.RUNNING: return '运行中';
    case TASK_STATUS.PAUSE: return '暂停';
    case TASK_STATUS.FINISHED: return '完成';
    case TASK_STATUS.FAILED: return '失败';
    default: return '未知任务状态';
  }
};

// 子任务状态start
export const SUBTASK_STATUS = {
  INIT: 1,
  RUNNING: 2,
  SUSPEND: 3,
  FINISHED: 4,
  EXECUTABLE: 5,
  FAILED: 6,
};
// 根据子任务状态获取子任务状态名称
export const getSubtaskStatusName = (taskStatus) => {
  switch (Number(taskStatus)) {
    case SUBTASK_STATUS.INIT: return '初始';
    case SUBTASK_STATUS.RUNNING: return '运行中';
    case SUBTASK_STATUS.SUSPEND: return '暂停';
    case SUBTASK_STATUS.FINISHED: return '完成';
    case SUBTASK_STATUS.EXECUTABLE: return '待执行';
    case SUBTASK_STATUS.FAILED: return '失败';
    default: return '未知任务状态';
  }
};
// 任务状态end
// 任务 表全量更新start
export const TASK_UPDATEALL = {
  YES: 1, // 是
  NO: 0, // 否
};
export const getTaskUpdateAllName = (updateAll) => {
  switch (Number(updateAll)) {
    case TASK_UPDATEALL.YES: return '是';
    case TASK_UPDATEALL.NO: return '否';
    default: return '未知';
  }
};
// 任务 表全量更新end
// 任务状态end
// 任务 网页类型start
export const TASK_URLTYPE = {
  STATIC: 1, // 静态
  DYNAMIC: 2, // 动态
};
export const getUrlTypeName = (urlType) => {
  switch (Number(urlType)) {
    case TASK_URLTYPE.STATIC: return '静态';
    case TASK_URLTYPE.DYNAMIC: return '动态';
    default: return '未知';
  }
};
// 任务 网页类型end
// 任务 资源类型start
export const TASK_RESOURCETYPE = {
  FILE: 1, // 文件
  URLS: 2, // url列表
};
export const getResourceTypeName = (resourceType) => {
  switch (Number(resourceType)) {
    case TASK_RESOURCETYPE.FILE: return '文件';
    case TASK_RESOURCETYPE.URLS: return 'url列表';
    default: return '未知';
  }
};
// 任务 资源类型end

// 菜单数据
export const MENU_DATA = [
  {
    key: 'dashboard',
    name: '主页',
    path: '/dashboard',
    icon: 'desktop',
    role: ['ADMIN', 'SUPERADMIN'],
    isParent: false,
  },
  {
    key: 'sys',
    name: '系统管理',
    icon: 'schedule',
    role: ['ADMIN', 'SUPERADMIN'],
    isParent: true,
    subMenu: [
      {
        key: 'userManage',
        name: '用户管理',
        path: '/user',
        icon: 'file-add',
        role: ['ADMIN', 'SUPERADMIN'],
        isParent: false,
      },
    ],
  },
  {
    key: 'base',
    name: '基础信息',
    icon: 'database',
    role: ['ADMIN', 'SUPERADMIN'],
    isParent: true,
    subMenu: [
      {
        key: 'engineManage',
        name: '模板管理',
        path: '/engine/list',
        icon: 'database',
        role: ['ADMIN', 'SUPERADMIN'],
        isParent: false,
      },
    ],
  },
];
function getMenuKey(data, pathname, role) {
  let menuKey;
  data.forEach((menu) => {
    if (menu.role.indexOf(role) >= 0) {
      if (!menu.isParent) {
        if (pathname === menu.path) {
          menuKey = menu.key;
        }
      } else {
        const tmpKey = getMenuKey(menu.subMenu, pathname, role);
        if (tmpKey) {
          menuKey = tmpKey;
        }
      }
    }
  });
  return menuKey;
}
export const getMenuKeyByPathname = (pathname, role) => {
  const menuKey = getMenuKey(MENU_DATA, pathname, role);
  if (!menuKey) {
    return 'dashboard';
  } else {
    return menuKey;
  }
};

function getOpenKeys(data, menuKey, openKeys) {
  let hasMenuKey = false;
  data.forEach((menu) => {
    if (!menu.isParent) {
      if (menuKey === menu.key) {
        hasMenuKey = true;
      }
    } else if (getOpenKeys(menu.subMenu, menuKey, openKeys)) {
      openKeys.push(menu.key);
      hasMenuKey = true;
    }
  });
  return hasMenuKey;
}
export const getOpenKeysByMenuKey = (menuKey, data) => {
  const openKeys = [];
  getOpenKeys(data, menuKey, openKeys);
  return openKeys;
};

// export const getMenusByPathname = (pathname) => {
//   const menus = [];
//   if (pathname.indexOf('/') >= 0) {
//     for (const menu of MENU_DATA) {
//       if (menu.isParent && pathname.split('/')[0] === menu.key) {
//         // menus.push({
//         //   name: menu.name,
//         //   icon: menu.icon,
//         //   isParent: menu.isParent,
//         // });
//         for (const submenu of menu.subMenu) {
//           if (pathname === submenu.path) {
//             menus.push({
//               name: submenu.name,
//               icon: submenu.icon,
//               path: submenu.path,
//             });
//           }
//         }
//       }
//     }
//   } else {
//     for (const menu of MENU_DATA) {
//       if (!menu.isParent) {
//         if (pathname === menu.path) {
//           menus.push({
//             name: menu.name,
//             icon: menu.icon,
//             path: menu.path,
//           });
//         }
//       }
//     }
//   }
//   return menus;
// };
